<template>
  <view class="bg-white rounded-[20rpx] shadow-md mb-[48rpx] overflow-hidden">
    <view class="bg-[#e4f0e4] p-[24rpx] btops border-b border-gray-100 flex items-center justify-between" @doubleclick="$emit('toggle')">
      <text class="text-[28rpx] font-bold text-gray-800">全面健康评估</text>
      <IconFont
        v-show="false"
        :name="isExpanded ? 'arrow-up' : 'arrow-down'"
        size="12"
        color="#8bc34a"
        :class="['transition-transform duration-200', isExpanded ? 'rotate-180' : 'rotate-0']"
      />
    </view>
    <view v-show="true || isExpanded" class="p-[24rpx] transition-all duration-300">
      <text class="text-[24rpx] text-gray-600 block mb-[30rpx]">进行详细的健康评估，包括体格检查、生理功能、风险评估等</text>
      <nut-button type="danger" class="!rounded-[12rpx] mb-[24rpx]" shape="square" size="large" block @click="goToHealthAssessment">
        <template #icon>
          <IconFont font-class-name="iconfont" class-prefix="icon" name="-yiliao" size="16" color="#fff" />
        </template>
        开始全面健康评估
      </nut-button>
    </view>
  </view>
</template>

<script setup lang="ts">
import Taro from '@tarojs/taro'
import { IconFont } from '@nutui/icons-vue-taro'
import { useItemManagement } from '@/composables/useItemManagement'

interface Props {
  isExpanded: boolean
}

interface Emits {
  (e: 'toggle'): void
}

defineProps<Props>()
defineEmits<Emits>()

const { formData } = useItemManagement()

/**
 * 跳转到全面健康评估页面
 */
function goToHealthAssessment() {
  try {
    console.log("跳转到全面健康评估页面")

    // 构建跳转参数
    const params = new URLSearchParams()
    params.append("type", "allCareAssessment")

    if (formData.value.idNumber) {
      params.append("idNumber", formData.value.idNumber)
    }
    
    // 传递记录ID，确保 sub-form 页面能正确加载数据
    if (formData.value.id) {
      params.append("id", formData.value.id)
    }

    const url = `/pages/medical-record/sub-form?${params.toString()}`
    console.log("跳转URL:", url)

    Taro.navigateTo({
      url: url,
    })
  } catch (error) {
    console.error("跳转失败:", error)
    Taro.showToast({
      title: "跳转失败",
      icon: "error",
    })
  }
}
</script>

<style scoped lang="scss">
.btops {
  border-top: solid 6rpx #8bc34a;
}

.rotate-0 {
  transform: rotate(0deg);
}

.rotate-180 {
  transform: rotate(180deg);
}
</style>
